home *** CD-ROM | disk | FTP | other *** search
/ Champak 29 / Volume 29 - JOGO DISK .iso / Games / jungle_adventure.swf / scripts / __Packages / SSDrawing.as < prev    next >
Text File  |  2006-11-29  |  12KB  |  398 lines

  1. class SSDrawing
  2. {
  3.    static var GRADIENT_ALPHAS = [100,100];
  4.    static var GRADIENT_RATIOS = [0,255];
  5.    static var styles = {};
  6.    var edgeGroupMask = SSGlobal.EDGE_GROUPING_MASK;
  7.    var created = 0;
  8.    var stylePrepared = false;
  9.    var className = "SSDrawStyle";
  10.    function SSDrawing(obj)
  11.    {
  12.       if(!this.lightDirection)
  13.       {
  14.          this.lightDirection = SSGlobal.DRAW_LIGHT_DIRECTION;
  15.       }
  16.       this.inst = [];
  17.       this.iLayers = [];
  18.    }
  19.    function initStyle(force)
  20.    {
  21.       if(!SSDrawing.styles[this.className])
  22.       {
  23.          this.setup();
  24.          this.define();
  25.          this.defineFromXML();
  26.          this.prepare();
  27.          SSDrawing.styles[this.className] = this;
  28.       }
  29.    }
  30.    function init(points, edges)
  31.    {
  32.       this.points = points;
  33.       this.edges = edges;
  34.       this.__proto__.initStyle();
  35.       var _loc5_ = undefined;
  36.       var _loc4_ = undefined;
  37.       this.groups = [];
  38.       var _loc2_ = -1;
  39.       var _loc6_ = edges.length;
  40.       while((_loc2_ = _loc2_ + 1) < _loc6_)
  41.       {
  42.          if(_loc4_ != (_loc4_ = edges[_loc2_].props & this.edgeGroupMask))
  43.          {
  44.             this.groups.push(_loc5_ = [edges[_loc2_]]);
  45.             _loc5_.mask = _loc4_;
  46.          }
  47.          else
  48.          {
  49.             _loc5_.push(edges[_loc2_]);
  50.          }
  51.          edges[_loc2_].attributes = this.pickStyle(_loc4_);
  52.       }
  53.       if(this.groups.length > 1 && _loc5_ != edges[0] && _loc4_ == (edges[0].props & this.edgeGroupMask))
  54.       {
  55.          this.groups[0] = this.groups.pop().concat(this.groups[0]);
  56.          this.groups[0].mask = _loc4_;
  57.       }
  58.       this.process();
  59.    }
  60.    function process()
  61.    {
  62.       this.showInfo();
  63.    }
  64.    function calculateLighting(normal, ambient, diffuse, specular)
  65.    {
  66.       var _loc3_ = undefined;
  67.       if((_loc3_ = Math.sin(this.lightDirection.dot(normal) * 1.570796)) <= 0)
  68.       {
  69.          return new RGB(diffuse.r - (specular.r - diffuse.r) * _loc3_,diffuse.g - (specular.g - diffuse.g) * _loc3_,diffuse.b - (specular.b - diffuse.b) * _loc3_);
  70.       }
  71.       return new RGB(diffuse.r + (ambient.r - diffuse.r) * _loc3_,diffuse.g + (ambient.g - diffuse.g) * _loc3_,diffuse.b + (ambient.b - diffuse.b) * _loc3_);
  72.    }
  73.    function draw(root)
  74.    {
  75.       this.root = this.target = root;
  76.       this.target.clear();
  77.       this.created = 0;
  78.       var _loc3_ = this.inst;
  79.       var _loc2_ = -1;
  80.       var _loc4_ = _loc3_.length;
  81.       while((_loc2_ = _loc2_ + 1) < _loc4_)
  82.       {
  83.          _loc3_[_loc2_][0].apply(this,_loc3_[_loc2_][1]);
  84.       }
  85.    }
  86.    function instruction(method)
  87.    {
  88.       this.inst.push([method,arguments.slice(1)]);
  89.    }
  90.    function solidShape(color)
  91.    {
  92.       this.inst.push([this._solid,arguments]);
  93.    }
  94.    function bitmapShape(textureID, p)
  95.    {
  96.       var _loc9_ = _global.root.attachMovie(textureID,"tmp",834201);
  97.       var _loc12_ = _loc9_._width;
  98.       var _loc11_ = _loc9_._height;
  99.       _loc9_.removeMovieClip();
  100.       var _loc3_ = p.length;
  101.       var _loc6_ = undefined;
  102.       var _loc5_ = undefined;
  103.       var _loc8_ = undefined;
  104.       var _loc7_ = undefined;
  105.       _loc6_ = _loc8_ = p[0].x;
  106.       _loc5_ = _loc7_ = p[0].y;
  107.       while((_loc3_ = _loc3_ - 1) > 0)
  108.       {
  109.          _loc6_ = Math.min(p[_loc3_].x,_loc6_);
  110.          _loc5_ = Math.min(p[_loc3_].y,_loc5_);
  111.          _loc8_ = Math.max(p[_loc3_].x,_loc8_);
  112.          _loc7_ = Math.max(p[_loc3_].y,_loc7_);
  113.       }
  114.       var _loc10_ = Math.ceil((_loc8_ - _loc6_) / _loc12_);
  115.       var _loc13_ = Math.ceil((_loc7_ - _loc5_) / _loc11_);
  116.       this.inst.push([this._bitmapShape,[textureID,p,_loc6_,_loc5_,_loc12_,_loc11_,_loc10_,_loc10_ * _loc13_]]);
  117.    }
  118.    function gradientShape()
  119.    {
  120.       this.inst.push([this._gradient,arguments]);
  121.    }
  122.    function assetStrip(linkageID, from, to, tile, skewOnX, skewOnY)
  123.    {
  124.       if(linkageID == null || from == null || to == null)
  125.       {
  126.          return undefined;
  127.       }
  128.       var _loc3_ = new Vector(to.x - from.x,to.y - from.y,0);
  129.       if(skewOnX == null)
  130.       {
  131.          skewOnX = true;
  132.       }
  133.       if(skewOnY == null)
  134.       {
  135.          skewOnY = true;
  136.       }
  137.       var _loc4_ = Math.atan2(_loc3_.y,_loc3_.x) * 180 / 3.141592653589793;
  138.       this.inst.push([this._assetStrip,[linkageID,from.x,from.y,_loc3_.length,tile,!skewOnX ? 0 : _loc4_,!skewOnY ? 0 : _loc4_]]);
  139.    }
  140.    function textureStrip(linkageID, from, to, tile, skewX)
  141.    {
  142.       if(linkageID == null || from == null || to == null)
  143.       {
  144.          return undefined;
  145.       }
  146.       var _loc3_ = new Vector(to.x - from.x,to.y - from.y,0);
  147.       this.inst.push([this._assetStrip,[linkageID,from.x,from.y,_loc3_.length,tile,!skewX ? 0 : skewX,Math.atan2(_loc3_.y,_loc3_.x) * 180 / 3.141592653589793]]);
  148.    }
  149.    function transform()
  150.    {
  151.       if(arguments.length)
  152.       {
  153.          this.inst.push([this._transform,arguments]);
  154.       }
  155.    }
  156.    function _transform(x, y, rot)
  157.    {
  158.       this.target._x = x;
  159.       this.target._y = y;
  160.       this.target._rotation = rot;
  161.    }
  162.    function _assetStrip(linkageID, x, y, len, tile, skewX, skewY)
  163.    {
  164.       var _loc13_ = undefined;
  165.       var _loc8_ = skewX != skewY;
  166.       if(_loc8_)
  167.       {
  168.          var _loc4_ = MovieClipSkew.create(this.target,null,"mc" + this.created,++this.created);
  169.          _loc4_.skew(skewX,skewY);
  170.       }
  171.       else
  172.       {
  173.          _loc4_ = this.target.createEmptyMovieClip("mc" + this.created,++this.created);
  174.          _loc4_._rotation = skewX;
  175.       }
  176.       _loc4_._x = x;
  177.       _loc4_._y = y;
  178.       var _loc3_ = _loc4_.attachMovie(linkageID,"m0",0);
  179.       var _loc5_ = _loc3_._width;
  180.       var _loc7_ = 1;
  181.       if(tile)
  182.       {
  183.          var _loc2_ = _loc7_ = Math.max(1,Math.round(len / _loc5_));
  184.          while(_loc2_ = _loc2_ - 1)
  185.          {
  186.             _loc3_ = _loc4_.attachMovie(linkageID,"m" + _loc2_,_loc2_);
  187.             _loc3_._x = _loc2_ * _loc5_;
  188.          }
  189.       }
  190.       if(_loc8_)
  191.       {
  192.          _loc4_.asset._xscale = len / (!tile ? _loc5_ : _loc7_ * _loc5_) * 100 + 1;
  193.       }
  194.       else
  195.       {
  196.          _loc4_._xscale = len / (!tile ? _loc5_ : _loc7_ * _loc5_) * 100;
  197.       }
  198.    }
  199.    function createTarget(targetName, depth, linkageID)
  200.    {
  201.       if(linkageID != null)
  202.       {
  203.          this.inst.push([linkageID != null ? this._createAssetTarget : this._createEmptyTarget,arguments]);
  204.       }
  205.    }
  206.    function setTarget(targetName)
  207.    {
  208.       this.inst.push([this._setTarget,arguments]);
  209.    }
  210.    function setLayer(layerNum)
  211.    {
  212.       if(this.iLayers[layerNum])
  213.       {
  214.          this.goRootTarget("mc" + layerNum);
  215.       }
  216.       else
  217.       {
  218.          this.inst.push([this._setLayer,arguments]);
  219.          this.iLayers[layerNum] = true;
  220.       }
  221.    }
  222.    function _setLayer(num)
  223.    {
  224.       this.target = this.root.createEmptyMovieClip("mc" + num,num);
  225.    }
  226.    function goRoot()
  227.    {
  228.       this.inst.push([this._goRoot,arguments]);
  229.    }
  230.    function goRootTarget()
  231.    {
  232.       this.inst.push([this._goRootTarget,arguments]);
  233.    }
  234.    function attachAndPlaceMovie()
  235.    {
  236.       this.inst.push([this._attachAndPlaceMC,arguments]);
  237.    }
  238.    function showInfo()
  239.    {
  240.       this.inst.push([this._showInfo]);
  241.    }
  242.    function _solid(color, p)
  243.    {
  244.       var _loc5_ = this.target;
  245.       _loc5_.beginFill(color);
  246.       var _loc3_ = undefined;
  247.       if(arguments.length > 2)
  248.       {
  249.          var _loc6_ = arguments.length;
  250.          while(_loc6_ = _loc6_ - 1)
  251.          {
  252.             _loc3_ = p = arguments[_loc6_].length;
  253.             _loc5_.moveTo(p[0].x,p[0].y);
  254.             while((_loc3_ = _loc3_ - 1) > -1)
  255.             {
  256.                _loc5_.lineTo(p[_loc3_].x,p[_loc3_].y);
  257.             }
  258.          }
  259.       }
  260.       else
  261.       {
  262.          _loc3_ = p.length;
  263.          _loc5_.moveTo(p[0].x,p[0].y);
  264.          while((_loc3_ = _loc3_ - 1) > -1)
  265.          {
  266.             _loc5_.lineTo(p[_loc3_].x,p[_loc3_].y);
  267.          }
  268.       }
  269.       _loc5_.endFill();
  270.    }
  271.    function _gradient(type, colors, alphas, ratios, matrix, p)
  272.    {
  273.       var _loc4_ = this.target;
  274.       _loc4_.beginGradientFill(type,colors,alphas,ratios,matrix);
  275.       var _loc2_ = p.length;
  276.       _loc4_.moveTo(p[0].x,p[0].y);
  277.       while((_loc2_ = _loc2_ - 1) > -1)
  278.       {
  279.          _loc4_.lineTo(p[_loc2_].x,p[_loc2_].y);
  280.       }
  281.       _loc4_.endFill();
  282.    }
  283.    function _bitmapShape(tileID, p, l, t, w, h, tw, i)
  284.    {
  285.       var _loc3_ = undefined;
  286.       var _loc7_ = this.target.createEmptyMovieClip("_T" + this.created,++this.created);
  287.       _loc7_._x = l;
  288.       _loc7_._y = t;
  289.       while((i = i - 1) > -1)
  290.       {
  291.          _loc3_ = _loc7_.attachMovie(tileID,"m" + i,i);
  292.          _loc3_._x = i % tw * w;
  293.          _loc3_._y = Math.floor(i / tw) * h;
  294.       }
  295.       var _loc6_ = this.target.createEmptyMovieClip("_F" + this.created,++this.created);
  296.       _loc6_.beginFill(0);
  297.       i = p.length;
  298.       _loc6_.moveTo(p[0].x,p[0].y);
  299.       while(i = i - 1)
  300.       {
  301.          _loc6_.lineTo(p[i].x,p[i].y);
  302.       }
  303.       _loc6_.endFill();
  304.       _loc7_.setMask(_loc6_);
  305.    }
  306.    function _createEmptyTarget(name, depth)
  307.    {
  308.       if(name == null)
  309.       {
  310.          name = "CLIP" + this.created;
  311.       }
  312.       else if(this.target[name])
  313.       {
  314.          return undefined;
  315.       }
  316.       this.target.createEmptyMovieClip(name,!depth ? this.created : depth);
  317.       this.created = this.created + 1;
  318.    }
  319.    function _createAssetTarget(name, depth, linkageID)
  320.    {
  321.       if(name == null)
  322.       {
  323.          name = "CLIP" + this.created;
  324.       }
  325.       else if(this.target[name])
  326.       {
  327.          return undefined;
  328.       }
  329.       this.target.attachMovie(linkageID,name,!depth ? this.created : depth);
  330.       this.created = this.created + 1;
  331.    }
  332.    function _createTarget(name, depth, linkageID)
  333.    {
  334.       if(this.target[name])
  335.       {
  336.          return undefined;
  337.       }
  338.       if(name == null)
  339.       {
  340.          name = "mc" + this.created;
  341.       }
  342.       if(linkageID != null)
  343.       {
  344.          this.target.attachMovie(linkageID,name,!depth ? this.created : depth);
  345.       }
  346.       else
  347.       {
  348.          this.target.createEmptyMovieClip(name,!depth ? this.created : depth);
  349.       }
  350.       this.created = this.created + 1;
  351.    }
  352.    function _setTarget(name)
  353.    {
  354.       this.target = this.target[name];
  355.    }
  356.    function _goRoot()
  357.    {
  358.       this.target = this.root;
  359.    }
  360.    function _goRootTarget(name)
  361.    {
  362.       this.target = this.root[name];
  363.    }
  364.    function _attachAndPlaceMC(assetID, depth, x, y)
  365.    {
  366.       var _loc2_ = this.target.attachMovie(assetID,assetID + "_" + depth,depth);
  367.       _loc2_._x = x;
  368.       _loc2_._y = y;
  369.    }
  370.    function _showInfo()
  371.    {
  372.       var _loc4_ = this.edges.length;
  373.       if(this.target != this.root)
  374.       {
  375.          this.target = this.root;
  376.       }
  377.       var _loc3_ = this.target.createEmptyMovieClip("info",65535);
  378.       var _loc2_ = undefined;
  379.       while((_loc4_ = _loc4_ - 1) > -1)
  380.       {
  381.          _loc2_ = this.edges[_loc4_];
  382.          _loc3_.lineStyle(0,(_loc2_.props & 1) == 0 ? 13421772 : 16711680);
  383.          _loc3_.moveTo(_loc2_.a.x + _loc2_.span.x,_loc2_.a.y + _loc2_.span.y);
  384.          _loc3_.lineTo(_loc2_.a.x,_loc2_.a.y);
  385.          _loc3_.lineStyle(3,255);
  386.          _loc3_.moveTo(_loc2_.a.x + _loc2_.span.x * 0.5,_loc2_.a.y + _loc2_.span.y * 0.5);
  387.          _loc3_.lineTo(_loc2_.a.x + _loc2_.span.x * 0.5 + _loc2_.normal.x * 30,_loc2_.a.y + _loc2_.span.y * 0.5 + _loc2_.normal.y * 30);
  388.          _loc3_.lineStyle(3,65280);
  389.          _loc3_.moveTo(_loc2_.a.x,_loc2_.a.y);
  390.          _loc3_.lineTo(_loc2_.a.x + _loc2_.a.normal.x * 30,_loc2_.a.y + _loc2_.a.normal.y * 30);
  391.       }
  392.    }
  393.    function toString()
  394.    {
  395.       return "DrawStyle " + this.className;
  396.    }
  397. }
  398.